#include<bits/stdc++.h>
using namespace std;
const int maxn = 5005;
const int INF = maxn*maxn;
bool a[maxn];
int dp[maxn][maxn];
int n, m;
vector<int> pos;
int main() {
  cin>>n;
  for(int i=0; i<n; ++i) cin>>a[i];
  for(int i=0; i<n; ++i) {
    if(a[i]) pos.push_back(i);
  }
  m = pos.size();
  for(int i=0; i<=n; ++i)
    for(int j=0; j<=m; ++j)
      dp[i][j]=INF;
  dp[0][0] = 0;
  for(int i=0; i<n; ++i) {
    for(int j=0; j<=m; ++j) {
      if(dp[i][j]>=INF) continue;
      dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
      if(j<m && a[i]==0) {
        dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+abs(i-pos[j]));
      }
    }
  }
  /*for(int i=0; i<=n; ++i) {
    for(int j=0; j<=m; ++j) {
      cout<<dp[i][j]<<' ';
    }
    cout<<endl;
  }*/
  cout<<dp[n][m]<<endl;
}
